package ioperations;

import book.Book;
import book.bookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation {
    public void work(bookList BookList) {
        System.out.println("借阅图书.......");

        System.out.println("请输入你要借阅的书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        int useSize = BookList.getUsesize();

        for (int i = 0; i < useSize; i++) {
            Book book = BookList.getBook(i);

            if (book.getName().equals(name)) {
                //要写在里面，不然会一直提示借出
                if(book.isBorrowed() == true){
                    System.out.println("这本书已经被借出了");
                    return;
                }
                System.out.println("找到了这本书");
                book.setBorrowed(true);
                System.out.println("借阅成功");
                return;
            }
        }
        System.out.println("没有你要借阅的书");
    }
}
